package com.yehuishou.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yehuishou.dao.BackItemDao;
import com.yehuishou.dao.BidItemDao;
import com.yehuishou.dao.ModelDao;
import com.yehuishou.pojo.BackItem;
import com.yehuishou.pojo.BidItem;
import com.yehuishou.pojo.Item;
import com.yehuishou.pojo.Models;
import com.yehuishou.service.ModelService;


@Service
public class ModelServiceImpl  implements ModelService{

	
	@Resource
	private ModelDao modelDao;
	
	@Resource
	private BackItemDao backItemDao;
	
	@Resource
	private BidItemDao bidItemDao;
	
	
	@Override
	public List<Models> getModelByid(Integer pid) {
		// TODO Auto-generated method stub
		return modelDao.getModelById(pid);
	}

	@Override
	public void deleteOne(Integer mid) {
		modelDao.deleteOne(mid);
	}

	@Override
	public boolean checkModel(Models models) {
		
		Models models2 =modelDao.checkModel(models);
		if(models2==null) {
			return true;
		}else {
			
			return false;
		}
		
	}

	@Override
	public void addModel(Models models) {
		
		modelDao.addOneModel(models);
	}

	@Override
	public boolean checkmodelExsitItem(Integer mid) {
		
		boolean flag =true;
		BackItem ba = new BackItem();
		ba.setMid(mid);
	  List<BackItem> bas =backItemDao.getBack(ba);//根据型号查回收商品
	  
	  BidItem biditem = new BidItem();
	  biditem.setMid(mid);
	List<BidItem> bids =  bidItemDao.getAllbiditem(biditem);//根据型号查竞价商品
		
	List<Item> items =backItemDao.getItemsBymid(mid);
	
	if((bas!=null&&bas.size()>0)||(bids!=null&&bas.size()>0)||items!=null&&items.size()>0) {
		
		flag =false;
		
	}
	
	  return flag;
		
	}

}
